<template>
  <div class="header">
    <img class="logo" src="../../assets/img/logo.png"/>
    <div v-if="currentPage">
      <img class="admin" src="../../assets/img/admin.png"/>
      <span class="adminName">{{adminName}}</span>
      <img class="loginOut" src="../../assets/img/loginOut.png"/>
      <span class="loginOutName" @click="dialogVisible = true">退出登录</span>
    </div>

    <el-dialog title="退出系统" :visible.sync="dialogVisible" width="30%">
      <span>确定退出系统?</span>
      <span slot="footer" class="dialog-footer">
       <el-button @click="dialogVisible = false">取 消</el-button>
       <el-button type="primary" @click="logitOut">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { mapGetters } from "vuex";
  export default {
    props: {},
    created () {
      let userInfo = localStorage.getItem('userInfo')
      if (userInfo) 
      {
        this.adminName = JSON.parse(userInfo).account
      }
    },
    name: 'common-header',
    data () {
      return {
        dialogVisible: false,
        adminName: 'adminName',
      }
    },
    methods: {
      logitOut () {
        this.dialogVisible = false
        this.$router.push('/')
        // localStorage.removeItem('userInfo');
        this.$store.commit("getUserInfo")
      }
    },
    computed:
    {
      ...mapGetters({currentPage:"userInfo"})
    },
  }
</script>